﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace projekt_1._0
{
    public partial class Beszallitok : Form
    {
        private SqlConnection cn;
        private BeszallitokDal BeszallitokPeldany;
        private int pointer = 0;
        public Beszallitok()
        {
            BeszallitokPeldany = new BeszallitokDal();
            InitializeComponent();
        }

        private void FomenuG_Click(object sender, EventArgs e)
        {
            try
            {
                cn.Close();
                this.Visible = false;
                Fomenu Fomenu = new Fomenu();
                Fomenu.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a kapcsolat letrehozasanal" + ex);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            cn.Close();
            Application.Exit();
        }

        private void Beszallitok_Load(object sender, EventArgs e)
        {
            try
            {
 
                cn = new SqlConnection();
                cn.ConnectionString = "server=ECNEBYGAN-PC;Database=abprojekt;uid=ecneBygaN-PC\\ecneBygaN;Integrated Security=true;";
                cn.Open();
                BeszallitokPeldany.DgwFill(BeszallitokDgw, CegNevTb, cn);
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a serverhez valo kapcsolodasnal!" + ex);
            }
        }

        private void CegNevTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (CegNevTb.Text.ToString() == "")
                {
                    BeszallitokPeldany.DgwFill(BeszallitokDgw, CegNevTb, cn);
                }
                BeszallitokPeldany.DgwFill(BeszallitokDgw, CegNevTb, cn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Valamilyen hiba merult fel az adatok betoltesenel! \n" + ex.ToString());

            }
        }

        private void HelysegTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (HelysegTb.Text.ToString() == "")
                {
                    BeszallitokPeldany.DgwFill(BeszallitokDgw, CegNevTb, cn);
                }
                BeszallitokPeldany.SzuresHelyseg (BeszallitokDgw,HelysegTb, cn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Valamilyen hiba merult fel az adatok betoltesenel! \n" + ex.ToString());

            }

        }

        private void ModositL_Click(object sender, EventArgs e)
        {

        }

        private void UjB_Click(object sender, EventArgs e)
        {
            CodFiscalL.Visible = true;
            CodFiscalTb.Visible = true;
            CuiL.Visible = true;
            CuiTb.Visible = true;
            CegCimTb.Visible = true;
            CegNevL.Visible = true;
            CegHelysegL.Visible = true;
            CegHelysegTb.Visible = true;
            CegCimTb.Visible = true;
            CegCimL.Visible = true;
            BankNevL.Visible = true;
            BankNevTb.Visible = true;
            BankSzamlaL.Visible = true;
            BankSzamlaTb.Visible = true;
            NevL.Visible = true;
            NevTb.Visible = true;
            TelefonLb.Visible = true;
            TelefonTb.Visible = true;
            MentesG.Visible = true;
            MegseG.Visible = true;
            UjB.Visible = false;
            UjL.Visible = false;
            ModositG.Visible = false;
            ModositL.Visible = false;
            TorlesG.Visible = false;
            TorlesL.Visible = false;
            FomenuG.Visible = false;
            KilepG.Visible = false;
            CegNevL.Visible = false;
            CegNevTb.Visible = false;
            HelysegL.Visible = false;
            HelysegTb.Visible = false;
            pointer = 1;
                   
        }

        private void MegseG_Click(object sender, EventArgs e)
        {
            CodFiscalL.Visible = false;
            CodFiscalTb.Visible = false;
            CuiL.Visible = false;
            CuiTb.Visible = false;
            CegCimTb.Visible = false;
            CegNevL.Visible = false;
            CegHelysegL.Visible = false;
            CegHelysegTb.Visible = false;
            CegCimTb.Visible = false;
            CegCimL.Visible = false;
            BankNevL.Visible = false;
            BankNevTb.Visible = false;
            BankSzamlaL.Visible = false;
            BankSzamlaTb.Visible = false;
            NevL.Visible = false;
            NevTb.Visible = false;
            TelefonLb.Visible = false;
            TelefonTb.Visible = false;
            MentesG.Visible = false;
            MegseG.Visible = false;
            UjB.Visible = true;
            UjL.Visible = true;
            ModositG.Visible = true;
            ModositL.Visible = true;
            TorlesG.Visible = true;
            TorlesL.Visible = true;
            FomenuG.Visible = true;
            KilepG.Visible = true;
            CegNevL.Visible = true;
            CegNevTb.Visible = true;
            HelysegL.Visible = true;
            HelysegTb.Visible = true;
            CodFiscalTb.Clear();
            CuiTb.Clear();
            NevTb.Clear();
            CegHelysegTb.Clear();
            CegCimTb.Clear();
            TelefonTb.Clear();
            BankNevTb.Clear();
            BankSzamlaTb.Clear();
            pointer = 0;
        }

        private void MentesG_Click(object sender, EventArgs e)
        {
            if (pointer == 1)
            {
                try
                {
                    if (BeszallitokPeldany.Mentes(cn) == true)
                    {
                        CodFiscalL.Visible = false;
                        CodFiscalTb.Visible = false;
                        CuiL.Visible = false;
                        CuiTb.Visible = false;
                        CegCimTb.Visible = false;
                        CegNevL.Visible = false;
                        CegHelysegL.Visible = false;
                        CegHelysegTb.Visible = false;
                        CegCimTb.Visible = false;
                        CegCimL.Visible = false;
                        BankNevL.Visible = false;
                        BankNevTb.Visible = false;
                        BankSzamlaL.Visible = false;
                        BankSzamlaTb.Visible = false;
                        NevL.Visible = false;
                        NevTb.Visible = false;
                        TelefonLb.Visible = false;
                        TelefonTb.Visible = false;
                        MentesG.Visible = false;
                        MegseG.Visible = false;
                        UjB.Visible = true;
                        UjL.Visible = true;
                        ModositG.Visible = true;
                        ModositL.Visible = true;
                        TorlesG.Visible = true;
                        TorlesL.Visible = true;
                        FomenuG.Visible = true;
                        KilepG.Visible = true;
                        CegNevL.Visible = true;
                        CegNevTb.Visible = true;
                        HelysegL.Visible = true;
                        HelysegTb.Visible = true;
                        CodFiscalTb.Clear();
                        CuiTb.Clear();
                        NevTb.Clear();
                        CegHelysegTb.Clear();
                        CegCimTb.Clear();
                        TelefonTb.Clear();
                        BankNevTb.Clear();
                        BankSzamlaTb.Clear();
                        pointer = 0;
                        try
                        {
                            BeszallitokPeldany.DgwFill(BeszallitokDgw, CegNevTb, cn);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Hiba az ujratoltesnel " + ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Hiba az uj adat beszurasanaal " + ex);
                }
            }
            else if (pointer == 2)
            {
                if (BeszallitokPeldany.MentesModositasUtan(cn) == true)
                {
                    CodFiscalL.Visible = false;
                    CodFiscalTb.Visible = false;
                    CuiL.Visible = false;
                    CuiTb.Visible = false;
                    CegCimTb.Visible = false;
                    CegNevL.Visible = false;
                    CegHelysegL.Visible = false;
                    CegHelysegTb.Visible = false;
                    CegCimTb.Visible = false;
                    CegCimL.Visible = false;
                    BankNevL.Visible = false;
                    BankNevTb.Visible = false;
                    BankSzamlaL.Visible = false;
                    BankSzamlaTb.Visible = false;
                    NevL.Visible = false;
                    NevTb.Visible = false;
                    TelefonLb.Visible = false;
                    TelefonTb.Visible = false;
                    MentesG.Visible = false;
                    MegseG.Visible = false;
                    UjB.Visible = true;
                    UjL.Visible = true;
                    ModositG.Visible = true;
                    ModositL.Visible = true;
                    TorlesG.Visible = true;
                    TorlesL.Visible = true;
                    FomenuG.Visible = true;
                    KilepG.Visible = true;
                    CegNevL.Visible = true;
                    CegNevTb.Visible = true;
                    HelysegL.Visible = true;
                    HelysegTb.Visible = true;
                    CodFiscalTb.Clear();
                    CuiTb.Clear();
                    NevTb.Clear();
                    CegHelysegTb.Clear();
                    CegCimTb.Clear();
                    TelefonTb.Clear();
                    BankNevTb.Clear();
                    BankSzamlaTb.Clear();
                    pointer = 0;
                    try
                    {
                        BeszallitokPeldany.DgwFill(BeszallitokDgw, CegNevTb, cn);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Hiba az ujratoltesnel " + ex);
                    }
                }
            }

        }

        private void CodFiscalTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitCodFiscal(CodFiscalTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Cod Fiscal inicializalasanal" + ex);
            }
        }

        private void CuiTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitCui(CuiTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a C.U.I. inicializalasanal" + ex);
            }
        }

        private void NevTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitCegNev(NevTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Cegnev inicializalasanal" + ex);
            }
        }

        private void CegHelysegTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitHelyseg(CegHelysegTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Ceg helyseg inicializalasanal" + ex);
            }
        }

        private void CegCimTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitCim(CegCimTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Ceg helyseg inicializalasanal" + ex);
            }
        }

        private void TelefonTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitTelefonb(TelefonTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a telefon inicializalasanal" + ex);
            }
        }

        private void BankNevTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitBankNev(BankNevTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Bank nev inicializalasanal" + ex);
            }
        }

        private void BankSzamlaTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.BeallitBankSzamal(BankSzamlaTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Bankszamla inicializalasanal" + ex);
            }
        }

        private void ModositG_Click(object sender, EventArgs e)
        {

            CodFiscalL.Visible = true;
            CodFiscalTb.Visible = true;
            CuiL.Visible = true;
            CuiTb.Visible = true;
            CegCimTb.Visible = true;
            CegNevL.Visible = true;
            CegHelysegL.Visible = true;
            CegHelysegTb.Visible = true;
            CegCimTb.Visible = true;
            CegCimL.Visible = true;
            BankNevL.Visible = true;
            BankNevTb.Visible = true;
            BankSzamlaL.Visible = true;
            BankSzamlaTb.Visible = true;
            NevL.Visible = true;
            NevTb.Visible = true;
            TelefonLb.Visible = true;
            TelefonTb.Visible = true;
            MentesG.Visible = true;
            MegseG.Visible = true;
            UjB.Visible = false;
            UjL.Visible = false;
            ModositG.Visible = false;
            ModositL.Visible = false;
            TorlesG.Visible = false;
            TorlesL.Visible = false;
            FomenuG.Visible = false;
            KilepG.Visible = false;
            CegNevL.Visible = false;
            CegNevTb.Visible = false;
            HelysegL.Visible = false;
            HelysegTb.Visible = false;
            pointer = 2;
            try
            {
                BeszallitokPeldany.FeltoltModositashoz(BeszallitokDgw, CodFiscalTb, CuiTb, NevTb, CegHelysegTb, CegCimTb, TelefonTb, BankNevTb, BankSzamlaTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba az adatok betoltesenel a modositashoz" + ex);
            }


        }

        private void TorlesG_Click(object sender, EventArgs e)
        {
            try
            {
                BeszallitokPeldany.Torol(BeszallitokDgw, cn);
                BeszallitokPeldany.DgwFill(BeszallitokDgw, NevTb, cn);

            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a torles soran!" + ex);
            }

        }



    }
}
